<template>
  <div class="layout">
    <div class="container">
      <mt-header class="layout-header cur-shadow" :title="title" fixed>
        <!-- <router-link to="/"> -->
        <mt-button v-if="noBackRoute.indexOf(curRoutePath)===-1" icon="back" onclick="window.history.go(-1)" slot="left"></mt-button>
        <!-- </router-link> -->
        <div slot="right">
          <i @click="linkToHome()" class="icon iconfont icon-gerenzhongxinx"></i>
          <i @click="linkToNav()" class="icon iconfont icon-caidanx"></i>
        </div>
      </mt-header>
      <div class="layout-view">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      viewportHeight: 600
    }
  },
  computed: {
    ...mapState({
      title: state => state.curTitle.title,
      noBackRoute: state => state.noBackRoute
    }),
    styles () {
      return {
        minHeight: this.viewportHeight - 72 + 'px'
      }
    },
    isCollapse () {
      return this.$store.state.toggleBar
    },
    curRoutePath () {
      return this.$route.path
    }
  },
  watch: {
    title (val) {
      return this.$store.state.title
    }
  },
  created () {
  },
  mounted () {
    window.addEventListener('resize', this.getViewportHeight(), false)
  },
  beforeDestroy () {
    window.removeEventListener('resize', this.getViewportHeight())
  },
  methods: {
    getViewportHeight () {
      this.viewportHeight = document.documentElement.clientHeight || document.body.clientHeight
      // return throttle(100, e => {
      //   this.viewportHeight = document.documentElement.clientHeight || document.body.clientHeight
      // })
    },
    linkToHome () {
      // let winHandler = window.open('')
      if (window.location.host === 'open.hxkjtest.com') {
        window.location.href = 'http://wap.hxkjtest.com'
      } else {
        window.location.href = 'http://wap.zhongyi9999.com'
      }
    },
    linkToNav () {
      // let winHandler = window.open('')
      if (window.location.host === 'open.hxkjtest.com') {
        window.location.href = 'http://wap.hxkjtest.com/nav.html'
      } else {
        window.location.href = 'http://wap.zhongyi9999.com/nav.html'
      }
    }
  }
}
</script>

<style lang="scss">
.layout {
  height: 100%;
  &-header {
    color: #666;
    background: $white;
    margin-bottom: 40px;
    height: 100px;
    .icon-gerenzhongxinx,
    .icon-caidanx {
      color: $red;
      font-size: 36px;
      font-weight: bold;
    }
    .icon-caidanx {
      margin-left: 20px;
    }
    .mint-header-title {
      color: $text-color;
    }
  }
  &-view {
    padding-top: 100px;
    height: 100%;
  }
  .container {
    height: 100%;
  }
  .container .is-fixed > h1 {
    font-size: 28px !important;
  }
}
</style>
